﻿using AiShow.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AiShow.WebSite
{
    public partial class Personal : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                // 读取用户资料
                var user = IdentityManager.ReadUser();
                if (user == null)
                {
                    Response.Redirect("login.aspx?ReturnUrl= Personal.aspx");
                }
                else {
                    imgAvatar.ImageUrl = user.Avatar ?? "/imgs/avatar.jpg";
                    lblNickName.Text = user.NickName ?? $"用户{user.Id}";
                    //lblSex.Text = user.Sex.ToString();
                    lblBirthday.Text = user.Birthday.HasValue ? user.Birthday.Value.ToString("M") : "未设置";
                    lblAddress.Text = user.Address ?? "未知地";
                    lblHobby.Text = user.Hobby ?? "未添加";
                    switch (user.Sex) {
                        case 1:
                            this.lblSex.Text = "小哥哥";
                            this.lblSex.CssClass += " bg-color-blue";
                            break;
                        case 2:
                             this.lblSex.Text = "小姐姐";
                             this.lblSex.CssClass += " bg-color-pink";
                             break;
                        case 0:
                        default:
                            this.lblSex.Text = "未知";
                            this.lblSex.CssClass += " bg-color-black";
                            break;
                    }
                }
                
                //        // 显示用户资料
                //        this.imgAvatar.ImageUrl = user.Avatar ?? "/imgs/avatar.jpg";
                //        this.lblNickName.Text = user.NickName ?? $"用户{user.Id}";
                //        switch (user.Sex)
                //        {
                //            case 1:
                //                this.lblSex.Text = "小哥哥";
                //                this.lblSex.CssClass += " bg-color-blue";
                //                break;
                //            case 2:
                //                this.lblSex.Text = "小姐姐";
                //                this.lblSex.CssClass += " bg-color-pink";
                //                break;
                //            case 0:
                //            default:
                //                this.lblSex.Visible = false;
                //                break;
                //        }
                //        this.lblAddress.Text = user.Address ?? "未知地";
                //        this.lblBirthday.Text = user.Birthday.HasValue ? user.Birthday.Value.ToString("M") : "未设置";
                //        this.lblHobby.Text = user.Hobby ?? "未添加";
            }
        }
        }
}